package org.ly.uap.client.authentication;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

public final class DefaultGatewayResolverImpl
        implements GatewayResolver {
    public static final String CONST_CAS_GATEWAY = "_const_cas_gateway_";

    public boolean hasGatewayedAlready(HttpServletRequest request, String serviceUrl) {
        HttpSession session = request.getSession(false);

        if (session == null) {
            return false;
        }

        boolean result = session.getAttribute("_const_cas_gateway_") != null;
        session.removeAttribute("_const_cas_gateway_");
        return result;
    }

    public String storeGatewayInformation(HttpServletRequest request, String serviceUrl) {
        request.getSession(true).setAttribute("_const_cas_gateway_", "yes");
        return serviceUrl;
    }
}
